<?php

namespace app\common\validate;


class Company extends BaseValidate
{
    /**
     * 验证规则
     */
    /**
     * 验证规则
     */
    protected $rule = [
        'name'                  => 'require|min:3|max:128|checkUnique',
        'concat_phone'  => 'require|length:5,30',
        'email' => 'email',
        'identificationswitch'  => 'in:0,1',
        'category'              => 'require|min:3|max:32',
        'management'            => 'in:0,1',
        'register_money'        => 'require|number|gt:1',
        'employment'            => 'require|min:3|max:32',
        'register_time'         => 'require',
        'register_place'        => 'require|min:3|max:128',
        'registry_office'       => 'require|min:4|max:128',
        'credit_code'           => 'require|min:5|max:32',
        'organization_code'     => 'require|min:5|max:32',
        'business_scope'        => 'require|min:5|max:5000',
        'province'              => 'require|integer',
        'city'                  => 'integer',
        'area'                  => 'integer',
        'detail'                => 'min:4|max:128',
        'is_plat'               => 'in:0,1',
    ];
    protected function checkUnique($value,$rule,$data)
    {
        $ids = input('ids', 0);
        $where = [];
        if ($ids) {
            $where  = ['name'=>$value, 'id' => ['neq', $ids]];
        } else {
            $where = ['name'=>$value];
        }

        $com = \app\common\model\Company::get($where);

        if ($com) {
            return '公司名称已经存在';
        }  else {
            return true;
        }
    }


    public function __construct(array $rules = [], $message = [], $field = [])
    {
        $this->field = [
            'name'                  => '企业名称',
            'concat_phone'          => '联系方式',
            'identificationswitch'  => '是否认证',
            'category'              => '企业类型',
            'management'            => '经营状态',
            'register_money'        => '注册资本',
            'employment'            => '行业类别',
            'register_time'         => '成立日期',
            'register_place'        => '注册地址',
            'registry_office'       => '登记机关',
            'credit_code'           => '统一社会信用代码',
            'organization_code'     => '组织机构代码',
            'business_scope'        => '经营范围',
            'province'              => '省',
            'city'                  => '市',
            'area'                  => '县',
            'detail'                => '详细地址',
            'is_plat'               => '是否为平台',
        ];
        parent::__construct($rules, $message, $field);
    }


}
